﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using Util;

namespace IterationLife.Extensions.Helpers
{
    /// <summary>
    /// Lambda辅助类
    /// </summary>
    public class LambdaHelper<T>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="expression"></param>
        /// <param name="helper"></param>
        public static string GetValue<TProperty>(Expression<Func<T, TProperty>> expression, HtmlHelper<T> helper)
        {
            var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
            return metadata.Model.SafeString();
        }
    }
}
